#!/bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
#   ./repeat-clone n vm_name
#

if [ $# -ne 2 ]; then 
   echo "usage: $0 n vm_name"
   exit 1
fi 
N=$1
VM=$2

SR=`xe sr-list --minimal name-label='NFS virtual disk storage'`
MASTER=`xe pool-list params=master --minimal`
START=$(date +%s)

echo "# vm_number cumulative_time load_average vhd_size"

perform () {
    i=$1
    TMP=`xe vm-clone vm=${VM} new-name-label=${VM}${i}`
    CURR=$(date +%s)
    DIFF=$(( ${CURR} - ${START} ))
    LOADAVG=`xe  host-data-source-query data-source=loadavg host=${MASTER}`
    VHDSIZE=` xe vdi-list --minimal sr-uuid=${SR} | sed -e 's/,/\n/g' | wc -l`
    echo "${i} ${DIFF} ${LOADAVG} ${VHDSIZE}"
}

for i in `seq 1 ${N}`; do 
    perform $i
done
